
const md5 = require("md5");

function getSign(body) {
    function getSignString(params) {
        let arr = [];
        for (let key in params) {
            if (!key || !params[key]) {
                continue;
            }
            arr.push(key + params[key]);
        }
        return arr.sort().join("");
    }
   
    let sign = getSignString(body); //获取签名字符串sign
    //验证密钥
    let confirmKey = "aec0613a3b8d4673cbd583be53d3af1d";
    //md5计算
    let md1 = md5(confirmKey + sign + confirmKey);
    return md1.toUpperCase();
}
function getQueryParam(sign, params) {
    let querys = [];
    params.sign = sign;
    Object.keys(params).map(key => {
        querys.push(`${key}=${params[key]}`);
    });
    return querys.join("&");
}

var body = {
    projectId: "395519115012096",
    appId: "5f63e04b2750d39bf10f3c71aafeee4c",
    startDate: 1575880046000,
    endDate: 1639038446730,
    time: Date.now(),
};
var body = {
    projectId: "395519115012096",
    appId: "5f63e04b2750d39bf10f3c71aafeee4c",
    deviceId: "7f983bd4-ad47-496c-ad0e-d2a430d02aee",
    time: Date.now(),
};
var body = {
    projectId: "395519115012096",
    appId: "5f63e04b2750d39bf10f3c71aafeee4c",
    deviceType:"TowerCrane",
    time: Date.now(),
};

const m = getSign(body);

//var url = `https://aecloud-test.glodon.com/gss/api/web/gss-v5-iot-rest-safe/projects/${body.projectId}/cranes/allInfo`;
//var url = `https://xmgl.glodon.com/gss/api/web/backend-service/gssapi/web/projects/${body.projectId}/safety/getSafetyRootGroupCategoryCount`;
var url = `https://xmgl.glodon.com/gss/api/web/smart-service/smart/api/web/projects/${body.projectId}/entities/simpleDevices`;

console.log(url +"?"+ getQueryParam(m,body));
